#!/bin/bash
#

nginx_cmd=/usr/local/nginx/sbin/nginx
nginx_pid_file=/usr/local/nginx/logs/nginx.pid

if [ -z $1 ];then
   echo "请输入以下参数: $0 <start|stop|restart|status|reload>"
   exit 11
fi

case $1 in
   start)
	$nginx_cmd
	if [ $? -eq 0 ];then
	 echo "nginx启动成功"
	else
	 echo "nginx启动失败"
	fi
	;;
   stop)
	$nginx_cmd -s stop
	;;
   restart)
	$nginx_cmd -s stop
	sleep 1
	$nginx_cmd
	;;
  status)
	if [ -f $nginx_pid_file ];then
	 echo "nginx(PID $(cat $nginx_pid_file)) is running"
	else
	 echo "nginx is stopped"
	fi
	;;
  reload)
	kill -HUP $(cat $nginx_pid_file)
	;;
  *)
	echo "请输入以下参数: $0<start|stop|restart|status|reload>"
	;;
esac
